﻿if (!window.UserControl) window.UserControl = {};

UserControl.DateRangePicker = function () {

    UserControl.DateRangePicker.superclass.constructor.apply(this, arguments);

    this.initComponents();
    this.bindEvents();
}

mini.extend(UserControl.DateRangePicker, mini.ButtonEdit, {

    uiCls: 'uc-daterangepicker',

    format: 'yyyy-MM-dd',

    setValue: function (value) {
        UserControl.DateRangePicker.superclass.setValue.call(this, value);
        this.setText(value);
    },

    within: function (e) {
        if (this.opened) return true;
        if (mini.isAncestor(this.el, e.target)) return true;
        return false;
    },

    initComponents: function () {
        var me = this;

        var input = this.getTextEl();
        $(input).dateRangePicker({

        }).bind('datepicker-opened', function () {

            me.opened = true;

        }).bind('datepicker-closed', function () {
            me.opened = false;

            me.focus();

        }).bind('datepicker-change', function (event, obj) {
            me.setValue(obj.value);
        });

        this.on("buttonclick", function (e) {

            setTimeout(function () {
                $(input).data('dateRangePicker').open();
            }, 20);

        });

    },
    bindEvents: function () {

    }

});

mini.regClass(UserControl.DateRangePicker, "DateRangePicker");